package org.open.sharedRadar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SignUp extends Activity {

	private EditText user;
    private EditText pass;
    private EditText name;	

	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.signup);				
	    
	    name = (EditText) findViewById(R.id.numeSignUpEditTxt);
	    user =  (EditText) findViewById(R.id.userSignUpEditTxt);                             
	    pass =  (EditText) findViewById(R.id.passSignUpEditTxt);
	    	   	   
	    Button buttonOK = (Button) findViewById(R.id.signUpBtn);
	    
	    buttonOK.setOnClickListener(new OnClickListener(){
		   public void onClick(View v) {
			   if(name.getText().length() < 1 || user.getText().length() < 1 || pass.getText().length() <1)
			   {
					Toast.makeText(getBaseContext(), "Trebuie sa intorduceti un nume de utilizator si o parola", Toast.LENGTH_SHORT).show();            	   
			   }
			   else
			   {
				 //SoapObject
				   	String nameSer = name.getText().toString();
					String userSer = user.getText().toString();
					String passSer = pass.getText().toString();
					try
					{					       
						   WebServiceHandler handler = new WebServiceHandler();
						   String result = handler.performSignUp(nameSer, userSer, passSer);
					       if(result.toUpperCase().equals("SUCCESS"))
						   {
					    	   //CurentUserProperties.getInstance().currentUserId = userSer;	
					    	   //CurentUserProperties.getInstance().currentPass = passSer;
					    	   //Integer radius = CurentUserProperties.getInstance().myRadius;
					    	   //if(radius == null)
					    		 //  CurentUserProperties.getInstance().myRadius = 5; 
					    	   Toast.makeText(getBaseContext(), "Va multumim pentru inregistrare.!", Toast.LENGTH_LONG).show();
					    	   Intent idAdd = new Intent(SignUp.this, Login.class);
					    	   startActivity(idAdd);              	   
						   }
						   else
						   {
							   Toast.makeText(getBaseContext(), "Inregistrare esuata! " + result, Toast.LENGTH_SHORT).show();            	   
						   }
					   }
					   catch (Exception aE)
					   {
					       aE.printStackTrace ();;
					   }
			   }
	    }
	    });
	    
	    Button buttonClose = (Button) findViewById(R.id.cancelSignUpBtn);
	    buttonClose.setOnClickListener(new OnClickListener(){
	    	public void onClick(View v) {			
	 		   try
	 		   {
	 			   	Intent idAdd = new Intent(SignUp.this,SharedRadar.class);
	 			  	startActivity(idAdd);
	 		   }
	 		   catch (Exception aE)
	 		   {
	 		       aE.printStackTrace ();;
	 		   }
	 			
	 		}
	    });    
	}
}